package org.example.iris.mapper;

import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface StudentFileMapper {

    @Insert("insert into student_files(student_id, file_id) values(#{studentId}, #{fileId})")
    void insertStudentFile(Integer studentId, Integer fileId);

    @Select("SELECT file.file_id, file_path from file JOIN student_files ON file.file_id = student_files.file_id WHERE student_id = #{studentId}")
    @MapKey("file_id")
    List<Map<Integer, String>> findFilesByStudentId(Integer studentId);


    @Select("SELECT student_id FROM student_files WHERE file_id = #{fileId}")
    Integer findStudentIdByFileId(Integer fileId);

    @Delete("DELETE FROM student_files WHERE file_id = #{fileId}")
    void deleteStudentFile(Integer fileId);
}
